
Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema:[],
    formData: {
      allowSingleChat: false,
      needGroupOpenID: false
    },
    title: '',
    result: '',
    remark: '',
    webUrl: '',
    apiName: '',
    showPrivacy: false
  },
  onUnload() {
  },
  onLoad(options) {
    const that = this;
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })
    
    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
    if(options.zh === 'wx.getGroupEnterInfo') {
      this.setData({
        schema: [
          {
            label:'开启后单聊下返回 open_single_roomid',
            prop:'allowSingleChat',
            type:'switch'
          },
          {
            label:'开启后返回用户在群(含单聊)下的 group_openid',
            prop:'needGroupOpenID',
            type:'switch'
          }
        ]
      })
    }
  },
  getFormData(e) {
    console.log('formdata==', e.detail.formData);
    this.setData({
      formData: e.detail.formData
    })
  },
  getGroupEnterInfo(e) {
    const that = this;
    wx.getGroupEnterInfo({
      allowSingleChat: this.data.formData.allowSingleChat,
      needGroupOpenID: this.data.formData.needGroupOpenID,
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
  },
})